package mybatis;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Demo {
    public static void main(String[] args) throws SQLException, ClassNotFoundException, IOException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/scott","root","123456");
        Statement stmt = conn.createStatement();

        String resource="mybatis.xml";
        InputStream inputStream= Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession=sqlSessionFactory.openSession();
        System.out.println(sqlSession);


        SqlSession sqlsession=sqlSessionFactory.openSession(true);
        System.out.println(sqlsession);
        DeptDao mapper=sqlsession.getMapper(DeptDao.class);
        int rows=mapper.update(new Dept(101,"大数据部","望城"));
        System.out.println(rows);
        sqlsession.close();
    }
}
